package com.example.zhidao.dao;

import com.example.zhidao.model.po.Blog;
import com.example.zhidao.model.po.Comments;
import com.example.zhidao.model.vo.BlogCountVo;
import com.example.zhidao.model.vo.BlogStatusNum;
import com.example.zhidao.model.vo.BlogUserNumVo;
import com.example.zhidao.model.vo.ClassifyNumVo;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BlogMapper extends MPJBaseMapper<Blog> {

//    用于事务的修改语句，在提交评论时给对应的数据库加一
    @Update("UPDATE blog SET comm = comm + 1 WHERE id = #{id}")
    public int setcomm(String id);

//    文章的点赞加一
    @Update("UPDATE blog SET good = good + 1 WHERE id = #{id}")
    public int addgood(String id);
    //    文章的点赞减一
    @Update("UPDATE blog SET good = good - 1 WHERE id = #{id}")
    public int delgood(String id);

    //    文章的收藏加一
    @Update("UPDATE blog SET collection = collection + 1 WHERE id = #{id}")
    public int addcollection(String id);
    //    文章的收藏减一
    @Update("UPDATE blog SET collection = collection - 1 WHERE id = #{id}")
    public int delcollection(String id);


    //    文章的收藏减一
    @Update("UPDATE blog SET view = view + 1 WHERE id = #{id}")
    public int addView(String id);


//    获取近一个月的创建博客的信息
    @Select("SELECT DATE(createtime) AS date, COUNT(*) AS num\n" +
            "FROM blog\n" +
            "WHERE createtime >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)\n" +
            "GROUP BY DATE(createtime) order by date asc;")
    public List<BlogCountVo> getMonthBlog();

//    获取各分类的数量
    @Select("select type,count(type) as num from blog group by type")
    public List<BlogStatusNum> getTypeNum();

//    获取博客最多的十个人
    @Select("select u.username,count(uid) as num from blog b  join user u on b.uid=u.id group by uid order by num desc limit 0,5 ")
    public List<BlogUserNumVo> getBlogUserNumVo();

//    获取各个分类的数据
    @Select("select c.name as cname, count(b.cid) as num\n" +
            "from classify c\n" +
            "left join blog b on b.cid = c.id\n" +
            "group by c.id;")
    public List<ClassifyNumVo> getClassifyVo();


//    xml 获取推举的文章博客
    public List<Blog> selRecommendfen(int type, @Param("pageNum")int pageName, @Param("pageSize")int pageSize);

//    xml 根据分类获取博客
    public List<Blog> selClassifyfen(int cid, @Param("pageNum")int pageName, @Param("pageSize")int pageSize);

//    xml 根据用户id获取对应的已发布的博客信息
    public List<Blog> selUidfen(String uid,@Param("pageNum")int pageName, @Param("pageSize")int pageSize);

//    xml 给后台，根据给的条件进行数据的获取（结果）
    public List<Blog> admingetblog(String title,String username,String cname,String condition,String sort,
                                   @Param("pageNum")int pageName, @Param("pageSize")int pageSize);


    //    xml 给后台，根据给的条件进行数据的获取(总数)
    public List<Blog> admingetblogtotal(String title,String username,String cname);



//    待审核（可有条件）博客
    public List<Blog> adminAwaitBlog(String title,String username,String cname,String condition,String sort,
                                     @Param("pageNum")int pageName, @Param("pageSize")int pageSize);
    //    xml 给后台，根据给的条件进行数据的获取(总数)
    public List<Blog> adminAwaitBlogTotal(String title,String username,String cname);


//    未通过
public List<Blog> adminNoPassBlog(String title,String username,String cname,String condition,String sort,
                                 @Param("pageNum")int pageName, @Param("pageSize")int pageSize);
    //    xml 给后台，根据给的条件进行数据的获取(总数)
    public List<Blog> adminNoPassBlogTotal(String title,String username,String cname);
}
